<template>
  <div class="my-container">
    <div class="header" v-if="user">
      <div class="base-info">
        <div class="left">
          <van-image
            :src="userData.photo"
            fit="cover"
            round
          />
          <span>{{userData.name}}</span>
        </div>
        <div class="right">
          <van-button round size="small" to="/userProfile">编辑资料</van-button>
        </div>
      </div>
      <div class="text-info">
        <div class="data-item">
          <span class="count">{{userData.art_count}}</span>
          <span class="text">头条</span>
        </div>
        <div class="data-item">
          <span class="count">{{userData.follow_count}}</span>
          <span class="text">关注</span>
        </div>
        <div class="data-item">
          <span class="count">{{userData.fans_count}}</span>
          <span class="text">粉丝</span>
        </div>
        <div class="data-item">
          <span class="count">{{userData.like_count}}</span>
          <span class="text">获赞</span>
        </div>
      </div>
    </div>
    <div v-else class="header" @click="$router.push('/login')">
      <div class="not-login">
        <img src="~@/assets/mobile.png" alt="" class="mobile-img" />
        <span class="login">登录/注册</span>
      </div>
    </div>
    <!-- 导航 -->
    <van-grid column-num="2" clickable class="grid-nav">
      <van-grid-item icon="photo-o" text="收藏" class="grid-item">
        <i slot="icon" class="iconfont icon-shoucang"></i>
        <span slot="text" style="margin-top: 4px">收藏</span>
      </van-grid-item>
      <van-grid-item icon="photo-o" text="历史" class="grid-item">
        <img src="@/assets/历史.png" alt="" slot="icon" />
        <span slot="text">历史</span>
      </van-grid-item>
    </van-grid>

    <!-- 宫格导航 -->
    <!-- 消息通知,小智同学,退出登录 -->
    <van-cell title="消息通知" is-link />
    <van-cell title="小智同学" is-link class="stu" />
    <van-cell
      v-if="user"
      title="退出登录"
      clickable
      class="awayLogin"
      @click="outLogin"
    />
  </div>
</template>

<script>
import { mapState } from "vuex";
import { getUserData } from "@/api/login.js"
export default {
  created(){
    if(this.user){
      this.userLoading()
    }
  },
  computed: {
    ...mapState(["user"]),
  },
  data(){
    return{
      userData:{}
    }
  },
  methods: {
    // 退出登录
    outLogin() {
      this.$dialog.confirm({
        title: "是否退出登录",
      })
        .then(() => {
          this.$store.commit('setUser',null)
        })
        .catch(() => {
        });
    },
    // 获取用户数据
    userLoading(){
      getUserData().then(res=>{
        // console.log(res)
        this.userData = res.data.data;
      })
    }
  },
};
</script>

<style lang="less" scoped>
.my-container {
  .header {
    height: 361px;
    background: url("~@/assets/banner.png");
    background-size: cover;
    overflow: hidden;
    .not-login {
      margin-top: 70px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }

    .mobile-img {
      width: 132px;
      height: 132px;
    }
    .login {
      color: #fff;
      font-size: 30px;
      margin-top: 30px;
    }
    .base-info {
      height: 231px;
      padding: 56px 32px 23px;
      box-sizing: border-box;
      display: flex;
      justify-content: space-between;
      .left {
        display: flex;
        align-items: center;
        .van-image {
          width: 132px;
          height: 132px;
          border: 5px solid #fff;
        }
        span {
          font-size: 30px;
          color: #fff;
          margin-left: 23px;
        }
      }
      .right {
        margin-top: 23px;
      }
    }
    .text-info {
      display: flex;
      .data-item {
        flex: 1;
        height: 130px;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        color: #fff;
        .count {
          font-size: 36px;
        }
        .text {
          font-size: 23px;
        }
      }
    }
  }
  .grid-nav {
    .grid-item {
      height: 141px;
      i.iconfont {
        font-size: 45px;
      }
      span {
        font-size: 28px;
      }
      .icon-shoucang {
        color: #eb5253;
      }
      img {
        width: 45px;
        height: 45px;
      }
    }
  }
  .awayLogin {
    text-align: center;
    color: #d86262;
  }
  .stu {
    margin-bottom: 10px;
  }
}
</style>